package com.rainy.guoran.business.manager.services.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rainy.guoran.business.manager.controller.vo.RoleSaveReqVO;
import com.rainy.guoran.business.manager.entity.Role;
import com.rainy.guoran.business.manager.enums.role.RoleTypeEnum;
import com.rainy.guoran.business.manager.mapper.RoleMapper;
import com.rainy.guoran.business.manager.services.RoleService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
    @Override
    public Long createRole(RoleSaveReqVO createReqVO) {
        Role role = new Role();
        BeanUtils.copyProperties(createReqVO, role);
        role.setType(RoleTypeEnum.SYSTEM.getType());
        return this.save(role) ? role.getId() : null;
    }

    @Override
    public void updateRole(RoleSaveReqVO updateReqVO) {
        Role role = new Role();
        BeanUtils.copyProperties(updateReqVO, role);
        this.updateById(role);
    }

    @Override
    public void deleteRole(Long id) {
        this.removeById(id);
    }

    @Override
    public Role getRole(Long id) {
        return this.getById(id);
    }
}
